package cn.itsy.dao.warntype;

import cn.itsy.pojo.Warnrule;
import cn.itsy.pojo.Warntype;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description:
 * @author: MisterGay
 * @date: 2019-06-03 11:15
 */
@Repository(value = "warnTypeDaoimpl")
public class WarnTypeDaoimpl implements WarnTypeDao {
    @Resource(name = "jdbcTemplate")
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<Warntype> qyertWarnTypeAll(String sql) {
        List<Warntype> query = this.jdbcTemplate.query(sql, new BeanPropertyRowMapper<Warntype>(Warntype.class));
        return query;
    }

    @Override
    public void insertWarnType(String sql, Warntype warntype) {
        this.jdbcTemplate.update(sql, warntype.getId(), warntype.getWtno(),
                warntype.getWtname(), warntype.getWtdesc(), warntype.getStatus());
    }

    @Override
    public void updateWarnType(String sql, Warntype warntype) {
        this.jdbcTemplate.update(sql, warntype.getId(), warntype.getWtno(), warntype.getWtname(),
                warntype.getWtdesc(), warntype.getStatus(), warntype.getId());
    }

    @Override
    public List<Warnrule> queryWarnruleById(String sql, Warntype warntype) {
        List<Warnrule> query = this.jdbcTemplate.query(sql, new BeanPropertyRowMapper<Warnrule>(Warnrule.class), warntype.getId());
        return query;
    }

    @Override
    public void updateWarnTypeStatusById(String sql, Warntype warntype) {
        this.jdbcTemplate.update(sql, warntype.getId());
    }
}
